﻿function ClientAddOnlineSupport()
{
    belongSite=document.getElementById("drpSelectSite").options[document.getElementById("drpSelectSite").selectedIndex].value;
    Url=SODC.CMPortal.FAQ.FAskQuestionsWP.GetViewFAQUrl(belongSite).value;
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    FilterFunc();
}

function ClientDeleteOnlineSupport(AskID) {
    Msg = SODC.CMPortal.FAQ.FAskQuestionsWP.GetConfirmDeleteMsg().value;
    if (confirm(Msg) == false) return;
    RetValue = SODC.CMPortal.FAQ.FAskQuestionsWP.ServerSideDeleteOnlineSupport(OnlineSupportId).value;
    if (RetValue.indexOf("ERROR") != -1) {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    FilterFunc();
}


function ClientSaveAddOnlineSupport()
{
    belongSite=document.getElementById("txtBelongSite").value;
    YahooNick=document.getElementById("txtYahooNick").value;
    SkypeNick=document.getElementById("txtSkypeNick").value;
    Description=document.getElementById("txtDescription").value;
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    RetValue = SharepointPortal.WebParts.OnlineSupport.AddOnlineSupport.ServerSideAddOnlineSupport(belongSite,language,YahooNick,SkypeNick,Description).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}


// For FAQ


function ClientDeleteFAQ(AskID)
{
    Msg = Portal.CDSP.FAskQuestionsWP.GetConfirmDeleteMsg().value;
    if (confirm(Msg) == false) return;
    RetValue = Portal.CDSP.FAskQuestionsWP.ServerSideDeleteFAQ(AskID).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    FilterFunc();
}

function ShowFormClientUpdateUrl(AskID)
{
    Url = Portal.CDSP.FAskQuestionsWP.GetShowUpdateForm(AskID).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 768px; dialogWidth: 1024px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    FilterFunc();
}

function SaveUpdateFAQ(AskID)
{
    AskAnswer = document.getElementById("txtAnswer").value;
    
    AskStatus = false;
    if(document.getElementById("chkStatus").checked)
        AskStatus = true;
    
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    RetValue = Portal.CDSP.UpdateFAskQuestionsWP.ServerSideUpdateFAQ(language, AskID, AskAnswer, AskStatus).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}


function FilterFunc() {
    document.getElementById("divProcessing").innerHTML = Portal.CDSP.FAskQuestionsWP.GetProcessingText().value;
    setTimeout("RealFilterFunc()", 10);
}



function RealFilterFunc() {
    belongSite = document.getElementById("drpSelectSite").options[document.getElementById("drpSelectSite").selectedIndex].value;
    // status = document.getElementById("divSelectFilter").options[document.getElementById("divSelectFilter").selectedIndex].value;
    //PageIndex = document.getElementById("divSelectPageLawDocumentType").options[document.getElementById("divSelectPageLawDocumentType").selectedIndex].value;   
    retValue = Portal.CDSP.FAskQuestionsWP.GetHtml(belongSite, 0).value;
    if (retValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";    
}

function JumPageLawDocumentType() {
    document.getElementById("divProcessing").innerHTML = Portal.CDSP.FAskQuestionsWP.GetProcessingText().value;
    setTimeout("RealJumpPageLawDocumentType()", 10);
}

function RealJumpPageLawDocumentType() {
    PageIndex = 0;
    belongSite = "vie";
    if (document.getElementById("divSelectPageLawDocumentType") != null) {
        PageIndex = document.getElementById("divSelectPageLawDocumentType").selectedIndex;
    }
    //Keyword = document.getElementById("txtKeyword").value;
    retValue = Portal.CDSP.FAskQuestionsWP.GetHtml(belongSite, PageIndex).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    document.getElementById("divOnlineSupportMain").innerHTML = retValue;
}

// End for FAQ



function ShowClientOnlineSupportItemUrlForm(OnlineSupportId)
{
    Url=SharepointPortal.WebParts.OnlineSupport.OnlineSupport.GetShowOnlineSupportItemsForm(OnlineSupportId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
}


function ClientShowAddOnlineSupportItemRootForm(OnlineSupportId)
{
    Url=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetAddOnlineSupportItemFormUrl(OnlineSupportId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    document.getElementById("divContentData").innerHTML=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetHtml(language,OnlineSupportId).value;
}

function ClientShowAddOnlineSupportItemSubForm(OnlineSupportId,ParentOnlineSupportItemId)
{
    Url=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetAddSubOnlineSupportItemFormUrl(OnlineSupportId,ParentOnlineSupportItemId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    document.getElementById("divContentData").innerHTML=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetHtml(language,OnlineSupportId).value;
}



function ClientShowUpdateOnlineSupportItemSubForm(OnlineSupportId,OnlineSupportItemId)
{
    Url=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetUpdateSubOnlineSupportItemFormUrl(OnlineSupportId,OnlineSupportItemId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    document.getElementById("divContentData").innerHTML=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetHtml(language,OnlineSupportId).value;
}

function ClientSaveAddOnlineSupportItem(OnlineSupportId)
{
    MaxItems=document.getElementById("txtMaxItems").value;
    SaveItems=SharepointPortal.WebParts.OnlineSupport.AddOnlineSupportItem.CreateSaveItemsObject(MaxItems).value;
    for(var Index=0;Index<SaveItems.length;Index++)
    {
        SaveItems[Index].Title=document.getElementById("txtTitle_"+Index).value;
        SaveItems[Index].Checked=document.getElementById("checkBox_"+Index).checked;
        SaveItems[Index].IndexOrder=document.getElementById("txtIndexOrder_"+Index).value;
        SaveItems[Index].AdvImageId = document.getElementById("txtAdvImageId_"+Index).value;
    }
    
    
    retValue=SharepointPortal.WebParts.OnlineSupport.AddOnlineSupportItem.ServerSideAddOnlineSupportItems(OnlineSupportId,SaveItems).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    window.close();
}

function DeleteOnlineSupportItem(OnlineSupportId,OnlineSupportIdItemId)
{
    ConfirmMsg=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetConfirmMsg().value;
    if(confirm(ConfirmMsg)==false)return;
    retValue=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.ServerSideDeleteOnlineSupportItem(OnlineSupportIdItemId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    alert(retValue);
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    document.getElementById("divContentData").innerHTML=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetHtml(language,OnlineSupportId).value;
}

function ClientSaveOnlineSupportItem(OnlineSupportId,OnlineSupportItemId)
{
    OnlineSupportItemName=document.getElementById("txtOnlineSupportItemName").value;
    IndexOrder=document.getElementById("txtIndexOrder").value;
    retValue=SharepointPortal.WebParts.OnlineSupport.UpdateOnlineSupportItem.ServerSideOnlineSupportItem(OnlineSupportItemId,OnlineSupportItemName,IndexOrder).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.close();
}

function ClientShowNewsItemForms(OnlineSupportId)
{
    Url=SharepointPortal.WebParts.OnlineSupport.OnlineSupport.GetShowNewsItemForm(OnlineSupportId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
}


function DetectAdvImageItem()
{
    selectedIndex=document.getElementById("divSelectAdvImage").selectedIndex;
    AdvImageId=document.getElementById("divSelectAdvImage").options[selectedIndex].value;
    value=SharepointPortal.WebParts.OnlineSupport.AddOnlineSupportItem.GetAdvImageText(AdvImageId).value;
    document.getElementById("divContentAdvImage").innerHTML=value;
}

function ClientSaveOnlineSupportItems()
{
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    Max=document.getElementById("txtMaxItems").value;
    for(var Index=0;Index<Max;Index++)
    {
        Id=document.getElementById("txtId_"+Index).value;
        Subject=document.getElementById("txtSubject_"+Index).value;
        IndexOrder=document.getElementById("txtIndexOrder_"+Index).value;
        
        SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.ServerSideSaveOnlineSupportItem(language,Id,Subject,IndexOrder).value;
    }   
    alert(SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.ServerSideGetSaveOkMsg().value);
}


function DetectHtmlBody(OnlineSupportId)
{
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    retValue=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetHtml(language,OnlineSupportId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("divContentData").innerHTML=retValue;
}


function DetectUpdateOnlineSupportBody(OnlineSupportId)
{
    language=document.getElementById("divSelectLanguage").options[document.getElementById("divSelectLanguage").selectedIndex].value;
    retValue=SharepointPortal.WebParts.OnlineSupport.UpdateOnlineSupport.GetSubject(language,OnlineSupportId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    document.getElementById("txtOnlineSupport").innerHTML=retValue;
}

function ClientPublishing(OnlineSupportId)
{
    ConfirmMsg=SharepointPortal.WebParts.OnlineSupport.OnlineSupport.GetConfirmPublishingMsg().value;
    if(confirm(ConfirmMsg)==false)return;

    document.getElementById("divProcessing").innerHTML=SharepointPortal.WebParts.OnlineSupport.OnlineSupport.GetProcessingText().value;
    setTimeout("RealClientPublishing('"+OnlineSupportId+"')",10);
}

function RealClientPublishing(OnlineSupportId)
{
    retValue=SharepointPortal.WebParts.OnlineSupport.OnlineSupport.ServerSidePublishing(OnlineSupportId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        document.getElementById("divProcessing").innerHTML="";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    alert(retValue);
}

function PublishingOnlineSupportItem(OnlineSupportItemId)
{
    ConfirmMsg=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetConfirmPublishingMsg().value;
    if(confirm(ConfirmMsg)==false)return;

    document.getElementById("divProcessing").innerHTML=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.GetProcessingText().value;
 
    setTimeout("RealPublishingOnlineSupportItem('"+OnlineSupportItemId+"')",10);
}

function RealPublishingOnlineSupportItem(OnlineSupportItemId)
{
    retValue=SharepointPortal.WebParts.OnlineSupport.OnlineSupportItems.ServerSideItemPublishing(OnlineSupportItemId).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        document.getElementById("divProcessing").innerHTML="";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    alert(retValue);
}



function JumPageStatus(belongSite) {
    var status = 0;            
    status = document.getElementById("divSelectFilter").value
    //result = document.getElementById("ContentSearchResult");
    retValue = Portal.CDSP.FAskQuestionsWP.GetHtml(belongSite, 0, status).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    } else {
        document.getElementById("ContentSearchResult").innerHTML = retValue;
    }
    document.getElementById("divProcessing").innerHTML = "";    
}



